#include <stdio.h>
#include <map>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
using namespace boost;

class TestShareFromThis;
typedef boost::function<void(shared_ptr<TestShareFromThis>)> testcallback;

class TestShareFromThis : public enable_shared_from_this<TestShareFromThis>
{
public:
    TestShareFromThis()
    {
        printf("i am construct.\n");
    }
    ~TestShareFromThis()
    {
        printf("i am destroyed.\n");
    }
    void testUseShareFromThis()
    {
        cb(shared_from_this());
    }
    testcallback cb;
};

void useSharedptr(shared_ptr<TestShareFromThis> sp)
{
    printf("using shared_ptr.\n");
    return;
}

using namespace std;
int main()
{
    TestShareFromThis sp;
    sp.cb = boost::bind(useSharedptr, _1);

    {
        sp.testUseShareFromThis();
    }

    printf("test\n");



    return 0;
}
